package com.cloudkinto.controller.order.input;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.bo.order.inbound.InboundPostToJdyBo;
import com.cloudkinto.bo.order.inbound.OrderInputQueryBo;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.order.input.OrderInputService;
import com.cloudkinto.vo.common.CommonBatchOperationVo;
import com.cloudkinto.vo.order.inbound.OrderInputDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 到货通知单（订单入库） 前端控制器
 * </p>
 *
 * @author long
 * @since 2024-11-04
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "Omp到货通知单模块")
@RequestMapping("/api/admin/omp/order/input")
public class OrderInputOmpController extends BaseController {
    private final OrderInputService orderInputService;

    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "到货通知单（订单入库）根据id查看详情", notes = "到货通知单（订单入库）根据id查看详情")
    @ApiResponses(@ApiResponse(code = 200, message = "请求成功", response = OrderInputDetailVo.class))
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", orderInputService.detail(id));
    }

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "到货通知单（订单入库）查询初始化", notes = "到货通知单（订单入库）查询初始化")
    public SingleResult pageInit() {
        return orderInputService.pageInit(getCompanyId(), getTenantId(), "omp", getCurrentUserId());
    }

    @UserSessionRequired
    @PostMapping("/listPage")
    @ApiOperation(value = "到货通知单（订单入库）查询（分页）", notes = "到货通知单（订单入库）查询（分页）")
    public PageResult listPage(@RequestBody @Validated OrderInputQueryBo bo) {
        bo.setTenantId(getTenantId());
        bo.setUserId(getCurrentUserId());
        bo.setSource("omp");
        return orderInputService.getListPage(bo);
    }

    @UserSessionRequired
    @PostMapping("/listPageStatusStatistics")
    @ApiOperation(value = "分页查询状态数量统计", notes = "分页查询状态数量统计")
    public SingleResult listPageStatus(@RequestBody @Validated OrderInputQueryBo bo) {
        bo.setTenantId(getTenantId());
        bo.setStatus(null);
        bo.setUserId(getCurrentUserId());
        bo.setSource("omp");
        return orderInputService.getListPageStatus(bo);
    }

    @UserSessionRequired
    @PostMapping("/excelExport")
    @ApiOperation(value = "导出到货通知单", notes = "导出到货通知单")
    public void excelExport(@RequestBody OrderInputQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setTenantId(getTenantId());
        bo.setUserId(getCurrentUserId());
        bo.setSource("omp");
        orderInputService.excelExport(bo, getTenantId(), getCompanyId(), getWarehouseId(), response);
    }

    @UserSessionRequired
    @GetMapping("/getNormalInboundImportTemplate")
    @ApiOperation(value = "获取常规导入模板", notes = "获取常规导入模板")
    public void getNormalInboundImportTemplate(HttpServletResponse response) throws IOException {
        orderInputService.getNormalInboundImportTemplate(response, getTenantId(), getCurrentUserId(), null, "omp");
    }

    @UserSessionRequired
    @GetMapping("/getTransferInboundImportTemplate")
    @ApiOperation(value = "获取备货中转导入模板", notes = "获取备货中转导入模板")
    public void getTransferInboundImportTemplate(HttpServletResponse response) throws IOException {
        orderInputService.getTransferInboundImportTemplate(response, getTenantId(), getCurrentUserId(), null, "omp");
    }

    @UserSessionRequired
    @PostMapping("/importNormalInbound")
    @ApiOperation(value = "常规导入", notes = "常规导入")
    public SingleResult importNormalInbound(MultipartFile file) {
        return SingleResult.success(orderInputService.importNormalInbound(file, getTenantId(), getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @PostMapping("/importTransferInbound")
    @ApiOperation(value = "备货中转导入", notes = "备货中转导入")
    public SingleResult importTransferInbound(MultipartFile file) {
        return SingleResult.success(orderInputService.importTransferInbound(file, getTenantId(), getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @PostMapping("/postToJdyInputOrder")
    @ApiOperation(value = "调拨发货计划推送到筋斗云", notes = "调拨发货计划推送到筋斗云")
    public SingleResult<CommonBatchOperationVo> postToJdyInputOrder(@RequestBody @Validated InboundPostToJdyBo bo) {
        return orderInputService.postToJdyInputOrder(bo);
    }
}